package com.tui.sort;
import java.util.ArrayList;
public class PinYinOrder {
	public static String getPinYin(String input) {
		ArrayList<OrderToken> tokens = new ArrayList<OrderToken>();
		float osver = 0;
		try
		{
			osver = Float.parseFloat(android.os.Build.VERSION.RELEASE.substring(0, 3));
		}
		catch(Exception e)
		{}
		if(osver >= 4.0f)
		{
			tokens = (ArrayList<OrderToken>) HanziToPinyinFour.getInstance().get(input);
		}
		else
		{
			tokens = (ArrayList<OrderToken>) HanziToPinyin.getInstance().get(input); 
		}
        StringBuilder sb = new StringBuilder();  
        if (tokens != null && tokens.size() > 0) {  
            for (OrderToken token : tokens) {  
                if (OrderToken.PINYIN == token.type) {  
                    sb.append(token.target);  
                } else {  
                    sb.append(token.source);  
                }  
            }  
        }  
        String strPinYin=sb.toString().toLowerCase();
        if(strPinYin!=null&&strPinYin.trim().length()>0)
        {
        	String firstChar = strPinYin.substring(0, 1);
    		if (firstChar.charAt(0) > 'z' || firstChar.charAt(0) < 'a')
    		{
    			firstChar = "#";
    			strPinYin="#"+strPinYin;
    		}
        }
        return strPinYin;  
    }  
}  




